home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_pwd.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. import unittest
  5. from test import test_support
  6. import pwd
  7.  
  8. class PwdTest(unittest.TestCase):
  9.     
  10.     def test_values(self):
  11.         entries = pwd.getpwall()
  12.         entriesbyname = { }
  13.         entriesbyuid = { }
  14.         for e in entries:
  15.             self.assertEqual(len(e), 7)
  16.             self.assertEqual(e[0], e.pw_name)
  17.             self.assert_(isinstance(e.pw_name, basestring))
  18.             self.assertEqual(e[1], e.pw_passwd)
  19.             self.assert_(isinstance(e.pw_passwd, basestring))
  20.             self.assertEqual(e[2], e.pw_uid)
  21.             self.assert_(isinstance(e.pw_uid, int))
  22.             self.assertEqual(e[3], e.pw_gid)
  23.             self.assert_(isinstance(e.pw_gid, int))
  24.             self.assertEqual(e[4], e.pw_gecos)
  25.             self.assert_(isinstance(e.pw_gecos, basestring))
  26.             self.assertEqual(e[5], e.pw_dir)
  27.             self.assert_(isinstance(e.pw_dir, basestring))
  28.             self.assertEqual(e[6], e.pw_shell)
  29.             self.assert_(isinstance(e.pw_shell, basestring))
  30.             entriesbyname.setdefault(e.pw_name, []).append(e)
  31.             entriesbyuid.setdefault(e.pw_uid, []).append(e)
  32.         
  33.         for e in entries:
  34.             self.assert_(pwd.getpwnam(e.pw_name) in entriesbyname[e.pw_name])
  35.             self.assert_(pwd.getpwuid(e.pw_uid) in entriesbyuid[e.pw_uid])
  36.         
  37.  
  38.     
  39.     def test_errors(self):
  40.         self.assertRaises(TypeError, pwd.getpwuid)
  41.         self.assertRaises(TypeError, pwd.getpwnam)
  42.         self.assertRaises(TypeError, pwd.getpwall, 42)
  43.         bynames = { }
  44.         byuids = { }
  45.         for n, p, u, g, gecos, d, s in pwd.getpwall():
  46.             bynames[n] = u
  47.             byuids[u] = n
  48.         
  49.         allnames = bynames.keys()
  50.         namei = 0
  51.         fakename = allnames[namei]
  52.         while fakename in bynames:
  53.             chars = map(None, fakename)
  54.             for i in xrange(len(chars)):
  55.                 if chars[i] == 'z':
  56.                     chars[i] = 'A'
  57.                     break
  58.                     continue
  59.                 if chars[i] == 'Z':
  60.                     continue
  61.                     continue
  62.                 chars[i] = chr(ord(chars[i]) + 1)
  63.                 break
  64.             else:
  65.                 namei = namei + 1
  66.                 
  67.                 try:
  68.                     fakename = allnames[namei]
  69.                 except IndexError:
  70.                     break
  71.  
  72.             fakename = ''.join(map(None, chars))
  73.         self.assertRaises(KeyError, pwd.getpwnam, fakename)
  74.         fakeuid = 4127
  75.         while fakeuid in byuids:
  76.             fakeuid = fakeuid * 3 % 65536
  77.         self.assertRaises(KeyError, pwd.getpwuid, fakeuid)
  78.  
  79.  
  80.  
  81. def test_main():
  82.     test_support.run_unittest(PwdTest)
  83.  
  84. if __name__ == '__main__':
  85.     test_main()
  86.  
  87.